package com.sxz.sbs.module.order.presenter;

import com.sxz.sbs.app.App;
import com.sxz.sbs.module.order.mode.OrderModifyStatusBean;
import com.sxz.sbs.module.order.view.IOrderModifyView;
import com.sxz.sbs.module.sale.mode.ImgBackBean;
import com.sxz.sbs.rx.RxPresenter;
import com.sxz.sbs.rx.RxSubscriber;
import com.sxz.sbs.rx.RxUtil;

import java.util.HashMap;
import java.util.List;

import okhttp3.MultipartBody;

/**
 * @author : tian
 * @date : 2018/04/18
 * @des :
 */

public class OrderModifyPresenter extends RxPresenter<IOrderModifyView>{
    /**
     * 获取订单修改状态
     * @param map
     */
    public void getOrderOrderStatus (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().getOrderModifyStatus(map)
                .compose(RxUtil.<List<OrderModifyStatusBean>>handleResult())
                .subscribeWith(new RxSubscriber<List<OrderModifyStatusBean>>(mView,true){
                    @Override
                    public void onNext(List<OrderModifyStatusBean> token) {
                        mView.onGetOrderModifyStatus(token);
                    }
                })
        );
    }
    /**
     * 编辑图片 删除图片
     * @param map
     */
    public void deletePhoto (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().deleteFile(map)
                .compose(RxUtil.<String>handleResult())
                .subscribeWith(new RxSubscriber<String>(mView,true){
                    @Override
                    public void onNext(String data) {
                        mView.onDeletePhotoSuccess();
                    }
                })
        );
    }
    /**
     * 上传图片
     */
    public void uploadPhoto (int fileType,List<MultipartBody.Part> file) {
        addSubscribe(App.getInstance().getApi().uploadFileList(fileType,file)
                .compose(RxUtil.<List<ImgBackBean>>handleResult())
                .subscribeWith(new RxSubscriber<List<ImgBackBean>>(mView){
                    @Override
                    public void onNext(List<ImgBackBean> data) {
                        mView.onUploadPhotoSuccess(data);
                    }
                })
        );
    }
    /**
     *  修改订单
     * @param map
     */
    public void modifyOrder (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().modifyOrder(map)
                .compose(RxUtil.<String>handleResult())
                .subscribeWith(new RxSubscriber<String>(mView,true){
                    @Override
                    public void onNext(String data) {
                        mView.onModifyOrderSuccess();
                    }
                })
        );
    }
}
